﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI;
using System.IO;

/// <summary>
/// Summary description for Untilities
/// </summary>

namespace VBDWebMobile
{
    public class Untilities
    {
        
        public Untilities()
        {
            
            //
            // TODO: Add constructor logic here
            //
        }
        public static int PageNumber(int total, int rows)
        {
            try
            {
                int nPage = total / rows;
                if (total % rows == 0)
                {
                    nPage = total / rows;
                }
                else
                {
                    nPage++;
                }
                return nPage;
            }
            catch (Exception)
            {

                return 0;
            }
            
        }
        public static string GetLocationInfo(double dLon, double dLat)
        {
            string szLocation = "";
            
            // Lay thong tin duong 

            if (dLon < 0.5 || dLat < 0.5)
                szLocation = "";
            else
            {
                byte[] info = null;//ls.GetGeoInfo(string.Format("{0}, {1}", dLon, dLat), "1000", "1000");

                if (info == null)
                    szLocation = "";
                else
                    szLocation = GeoInfoParser(info);
            }

            return szLocation;
        }
       static string GeoInfoParser(byte[] pBuffer)
        {
            UnicodeEncoding Unicode = new UnicodeEncoding();

            MemoryStream msr = new MemoryStream(pBuffer);
            BinaryReader br = new BinaryReader(msr);

            string szText = "";
            string szCurStreet = "";
            int nNameLen;

            //Street Name	
            nNameLen = br.ReadInt32() * 2;
            szText = Unicode.GetString(br.ReadBytes(nNameLen));

            szCurStreet = szText;

            //Ward Name
            nNameLen = br.ReadInt32() * 2;
            szText = Unicode.GetString(br.ReadBytes(nNameLen));
            szCurStreet += ", " + szText;

            //District Name
            nNameLen = br.ReadInt32() * 2;
            szText = Unicode.GetString(br.ReadBytes(nNameLen));
            szCurStreet += ", " + szText;

            //Province Name
            nNameLen = br.ReadInt32() * 2;
            szText = Unicode.GetString(br.ReadBytes(nNameLen));
            szCurStreet += ", " + szText;

            return szCurStreet;
        }
    }

}
